<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui">

    <f:view contentType="text/html">
        
        <h:head rendered="#{login.loggedIn}">
            <f:facet name="first">
                <meta content='text/html; charset=UTF-8' http-equiv="Content-Type"/>
                <title>ESA Music Webapp</title>
            </f:facet>
        </h:head>

        <!-- content is only rendered of the login state is true -->
        <h:body rendered="#{login.loggedIn}">
            <h:outputStylesheet library="css" name="default.css" />
            <p:layout fullPage="true">

                <p:layoutUnit position="north" size="50" resizable="true" closable="true" collapsible="true">
                    <b>ESA Music Webapp</b><br/>
                    Applied SOA to search music online on last.fm and chartlyrics 
                </p:layoutUnit>

                <p:layoutUnit position="south" size="50" closable="true" collapsible="true">
                    EsaMusicWebapp eine Projektarbeit im Kurs Enterprise Software Architecture WS 2012/2013
                </p:layoutUnit>

                <p:dialog id="passwordDialog" widgetVar="pwDlg" resizable="false"
                          header="Change Own Password"  modal="true">
                    <h:form id="passwordDialogForm">
                        <h:panelGrid columns="2" cellpadding="5" border="1">
                            old password:
                            <p:password id="oldPwdInp" value="#{search.oldPwdInp}"/>
                            new password:
                            <p:password id="newPwdInp" value="#{search.newPwdInp}"/>
                            <p:commandButton id="changePasswordBtn" value="Change password" actionListener="#{search.changePW()}" update="growl" ajax="false"/>
                            <p:commandButton id="deleteUserBtn" value="Delete my user" actionListener="#{search.deleteUser()}" update="growl" ajax="false"/>   
                        </h:panelGrid>
                    </h:form>
                </p:dialog>

                <p:layoutUnit position="center">
                    <h:form id="passwordForm">
                        <p:growl id="growl" showDetail="true"/>
                        <h:panelGrid columns="2" cellpadding="5" border="1">
                            <p:commandButton id="changePwDlgBtn" value="Change Password" onclick="pwDlg.show()"  type="button"/> 
                            <p:commandButton id="logoutBtn" value="Logout" actionListener="#{search.logout()}" ajax="false"/> 
                        </h:panelGrid>
                    </h:form>

                    <h:form id="form1">
                        <p:panel menuTitle="Search Panel" >
                            <h:panelGrid columns="2" cellpadding="5" border="1">
                                <h:outputText value="Title: "/>
                                <p:inputText id="titleInp" value="#{search.titleInp}"/>
                                <h:outputText value="Artist: "/>
                                <p:inputText id="artistInp" value="#{search.artistInp}"/>
                                <p:commandButton id="searchTitleBtn" value="Search" actionListener="#{search.searchTrack()}" ajax="false"/> 
                            </h:panelGrid>
                        </p:panel>
                    
                   
                    <p:dataTable id="musicTable" var="track"  rowKey="#{track.title}"
                                 selection="#{search.selectedTrack}" selectionMode="single"
                                 rows="20" value="#{search.trackList}" paginator="true">
                        <p:ajax event="rowSelect" update=":form1:trackDialog" oncomplete="dlg1.show()" />  

                        <f:facet name="header">
                            Music found according to search:
                        </f:facet>

                        <p:column headerText="Artist" sortBy="#{track.artist}">
                            <h:outputText value="#{track.artist}"/>
                        </p:column>
                        <p:column headerText="Title" sortBy="#{track.title}">
                            <h:outputText value="#{track.title}"/>
                        </p:column>
                        <p:column headerText="Cover">
                            <h:graphicImage style="height: 60px;width: 60px" url="#{track.imageUri}"/>
                        </p:column>
                    </p:dataTable>

                    <p:dialog id="trackDialog" widgetVar="dlg1" resizable="false"  header="Track Detail" >
                        <p:panelGrid columns="2">
                            <p:panelGrid columns="2" >
                                <h:outputText value="Title"/>
                                <h:outputText value="#{search.selectedTrack.title}"/>
                                <h:outputText value="Artist"/>
                                <h:outputText value="#{search.selectedTrack.artist}"/>
                                <h:outputText value="Lyric"/>
                                <h:inputTextarea rows="10" cols="100" readonly="true" value="#{search.selectedTrack.lyric}"/>
                                <h:outputText value="SampleUri"/>
                                <h:outputLink value="#{search.selectedTrack.sampleUri}">
                                    #{search.selectedTrack.sampleUri}
                                </h:outputLink>
                            </p:panelGrid>
                            <h:graphicImage height="60px" width="60px" url="#{search.selectedTrack.imageUri}" alt="Album Image" />
                        </p:panelGrid>
                    </p:dialog>
                </h:form>
                   
                </p:layoutUnit> <!-- end of center layoutUnit -->

            </p:layout> <!-- end of page layout -->
        </h:body>
    </f:view>
</html>
